package com.shengsiyuan.netty.sixthexample.server;

import com.shengsiyuan.netty.sixthexample.handler.CustomProtobufDecoder;
import com.shengsiyuan.netty.sixthexample.handler.CustomProtobufEncoder;
import com.shengsiyuan.netty.sixthexample.proto.MyDataInfo;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
@SuppressWarnings("all")
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        // 设置需要处理解码的类型 ,对应 .proto 文件中message的类型
        pipeline.addLast(new ProtobufDecoder(MyDataInfo.Message.getDefaultInstance()));
        pipeline.addLast(new ProtobufEncoder());
//        pipeline.addLast(new CustomProtobufDecoder());
//        pipeline.addLast(new CustomProtobufEncoder());
        pipeline.addLast(new ProtobufVarint32FrameDecoder());
        pipeline.addLast(new ProtobufVarint32LengthFieldPrepender());
        pipeline.addLast(new TestServerHandler());
    }
}
